/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kallsonys.session;

import com.kallsonys.object.Address;
import com.kallsonys.object.Customer;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author alladiab
 */
@Stateless
public class AddressFacade extends AbstractFacade<Address> {

    @PersistenceContext(unitName = "Kallsonys-WarPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public AddressFacade() {
        super(Address.class);
    }

    public List<Address> getByCustomerId(long customerId) {
        List<Address> p = null;

        Query queryByCustomerId = em.createNamedQuery("Address.findByCustumerId");
        queryByCustomerId.setParameter("customerid", new Customer(customerId));
        p = (List<Address>) queryByCustomerId.getResultList();

        return p;
    }
    
    
    public long CreateAddress( com.kallsonys.object.Address address )
    {
        this.create(address);
        
        return address.getAddressid();
    }
}
